﻿using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
using UnityEngine.Events;

/// <summary>
/// 把控件Script注册到UImanager
/// 可以直接查找 物体 把物体本身 注册到 UImanager
/// </summary>
public class UIBehaviour : MonoBehaviour
{
    void Awake()
    {
        UIManager.Instance.RegistGameObject(name, gameObject);
    }

    public void AddButtonListener(UnityAction action)
    {
        if (action != null)
        {
            Button btn = transform.GetComponent<Button>();
            btn.onClick.AddListener(action);
        }
    }

    public void RemoveButtonListener(UnityAction action)
    {
        if (action != null)
        {
            Button btn = transform.GetComponent<Button>();
            btn.onClick.RemoveListener(action);
        }
    }
    public void AddToogleListener(UnityAction<bool> action)
    {
        if (action != null)
        {
            Toggle btn = transform.GetComponent<Toggle>();
            btn.onValueChanged.AddListener(action);
        }
    }
    public void RemoveToogleListener(UnityAction<bool> action)
    {
        if (action != null)
        {
            Toggle btn = transform.GetComponent<Toggle>();
            btn.onValueChanged.RemoveListener(action);
        }
    }

    public void AddSlideListener(UnityAction<float> action)
    {
        if (action != null)
        {
            Slider btn = transform.GetComponent<Slider>();
            btn.onValueChanged.AddListener(action);
        }
    }

    public void RemoveSlideListener(UnityAction<float> action)
    {
        if (action != null)
        {
            Slider btn = transform.GetComponent<Slider>();
            btn.onValueChanged.RemoveListener(action);
        }
    }

    public void AddInputListener(UnityAction<string> action)
    {
        if (action != null)
        {
            InputField btn = transform.GetComponent<InputField>();
            btn.onValueChange.AddListener(action);
        }
    }

    public void RemoveInputListener(UnityAction<string> action)
    {
        if (action != null)
        {
            InputField btn = transform.GetComponent<InputField>();
            btn.onValueChange.RemoveListener(action);
        }
    }
}
